import sun.rmi.server.InactiveGroupException;

import java.util.ArrayList;
import java.util.List;

public class MyBinaryTree {

    //静态内部类
    static class BinaryTree {
        public int val;
        public BinaryTree left;
        public BinaryTree right;
        public BinaryTree(int val) {
            this.val = val;
        }
    }

    //头节点
    public BinaryTree root;

    //初始化一个二叉树
    public void initBinaryTree() {
        BinaryTree A = new BinaryTree(1);
        BinaryTree B = new BinaryTree(2);
        BinaryTree C = new BinaryTree(3);
        BinaryTree D = new BinaryTree(4);
        BinaryTree E = new BinaryTree(5);
        BinaryTree F = new BinaryTree(6);
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.right = F;
        root = A;
    }
    //二叉树的前序遍历
    public void preOrder(BinaryTree tree) {
        if( tree == null) {
            return;
        }
        System.out.print(tree.val+" ");
        preOrder(tree.left);
        preOrder(tree.right);
    }
    //二叉树的中序遍历
    public void inOrder(BinaryTree tree) {
        if( tree == null) {
            return;
        }
        preOrder(tree.left);
        System.out.print(tree.val+" ");
        preOrder(tree.right);
    }
    //二叉树的后序遍历
    public void postOrder(BinaryTree tree) {
        if( tree == null) {
            return;
        }
        preOrder(tree.left);
        preOrder(tree.right);
        System.out.print(tree.val+" ");
    }
}
